package com.complex.spring.advance.service.context;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
/**参照baza的 PropertyUtil写法
 * 基本做法是load InputStream
 * @author gao
 *
 */
public class PropertyUtil {
	public static Properties getProperty(String fileName)  {
        Properties p = new Properties();
        try {
        	//InputStream in = PropertyUtil.class.getResourceAsStream(fileName); 这样也可以
        	//将文件读取为InputStream  再从InputStream中解析成Properties
            InputStream in = PropertyUtil.class.getClassLoader().getResourceAsStream(fileName);
            p.load(in);
            in.close();
        } catch (Exception e1) {
            try {
                InputStream in = PropertyUtil.class.getResourceAsStream("/" + fileName);
                p.load(in);
                in.close();
            } catch (Exception e2) {
                try {
                    File f = new File(fileName);
                    FileInputStream fis = new FileInputStream(f);
                    p.load(fis);
                    fis.close();
                } catch (Exception e3) {
                    //TODO
                }
            }
        }
        return p;
    }
}
